﻿@{
    var webContext=WebSiteContext.Current;
    }
@if ((webContext.Web.IsRoot && webContext.IsAuthorized<DNA.Mvc.Controllers.WebFilesController>("Upload")) ||
    (User.IsWebOwner()))
{
    <div style="height: 25px;">
        @(
 Ajax.Dna().Button("btnUploadFile")
            .ChangeType(ButtonTypes.LinkButton)
            .LocText("RES_UPLOAD")
            .ImageIcons(Url.Content("~/content/images/icon_attach_16.png"))
            .GetHtml())
        @(Ajax.Dna().Uploader("btnUploadFile")
            .Options(opts =>
            {
                opts.Action = ViewData["Path"].ToString();
                opts.OnCompleted = "if (response!=\"OK\") $dna.showDlg(\""+Html.Global("RES_MESSAGE")+"\",response); else $(\"#WebFilesGrid_pager\").pager(\"reload\");";
            })
           .GetHtml())
    </div>
}
@{ Ajax.Dna().Grid<WebResourceInfo>()
        .Name("WebFilesGrid")
        .HtmlAttributes(new { style = "color:#000000;height:560px;" })
        .ShowScrollBar()
        .Options(opts =>
        {
            opts.OnRowSelected = "var _selVal=$(ui.row).find(\"input[type='hidden']\").val();$(\"#txtFileExplorerStatus\").val(_selVal); $(\"#previewImg\").attr(\"src\",_selVal+\"?thumb=true&w=100&h=150\").show();";
        })
        .ClientBind(Url.Action("GetFiles", "WebFiles", new { Area = "", url = ViewData["Path"].ToString() }))
        .Columns(columns =>
        {
            columns.Bound(file => file.Name).Title(Html.Global("RES_NAME")).ClientTemplate(@<text>
    <a href="${Url}" target="_blank" style="color: #000000;">
        <img src="@(Url.Action("MimeIcon", "WebFiles") + "?extension=${Extension}")" alt="${Extension}" class="d-icon" />${Name}
        <input type="hidden" value="${Url}" />
    </a>
    </text>).Width(400);
            columns.Bound(file => file.ContentType).Title(Html.Global("RES_CONTENTTYPE")).Width(120);
            columns.Bound(file => file.FileSize).Title(Html.Global("RES_FILESIZE")).Width(80).ClientTemplate(@<text>
    {{if FileSize>1000}} <span style="float: right;">{{= Math.round(FileSize/1024)}}k</span>
    {{else}} <span style="float: right;">${FileSize}k</span> {{/if}}
    </text>);
        })
    .Pagable()
    .Render();
}
@Html.StartupScripts()
